package com.example.prison.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.prison.entity.SystemInfo;
import com.example.prison.mapper.AreaManagementMapper;
import com.example.prison.service.SystemInfoService;
import com.example.prison.mapper.SystemInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author jiang
* @description 针对表【system_info】的数据库操作Service实现
* @createDate 2024-01-17 15:47:25
*/
@Service
public class SystemInfoServiceImpl extends ServiceImpl<SystemInfoMapper, SystemInfo>
    implements SystemInfoService{

    @Autowired
    private SystemInfoMapper systemInfoMapper;

    @Autowired
    private AreaManagementMapper areaManagementMapper;

    @Override
    public List<SystemInfo> get() {
        return systemInfoMapper.get();
    }

    @Override
    public int update(SystemInfo data, Integer id) {
        if(systemInfoMapper.get().size() > 1) {
            systemInfoMapper.deleteAll();
        }
        if(systemInfoMapper.get().size() < 1) {
            systemInfoMapper.add(data);
        }
        systemInfoMapper.update(data, id);
        return 1;
    }

    @Override
    public int updateIPAndPort(String ip, Integer port) {
        systemInfoMapper.updateIPAndPort(ip, port);
        areaManagementMapper.updateIPAndPort(ip, port);
        return 1;
    }

    @Override
    public SystemInfo one(){
        return systemInfoMapper.one();
    }


}




